package com.neuedu.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName WeatherListAdapter
 * @Author name
 * @Date 2025/4/8
 * Description
 */
public class WeatherListAdapter extends RecyclerView.Adapter<WeatherListAdapter.myViewHolder> {
    private List<WeatherListBean.DataBean> dataBeans = new ArrayList<>();
    private Context mContext;

    public WeatherListAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setDataBeans(List<WeatherListBean.DataBean> dataBeans) {
        this.dataBeans = dataBeans;
        notifyDataSetChanged();
    }

    public void clear(){
        dataBeans.clear();
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_weather_list,parent,false);
        myViewHolder holder = new myViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull myViewHolder holder, int position) {
        holder.tv_time.setText(dataBeans.get(position).getWeatherConditions());

        if (dataBeans.get(position).getWeatherConditions().equals("晴")){
            Glide.with(mContext).load(R.mipmap.ic_sun).into(holder.iv);
        }else {
            Glide.with(mContext).load(R.mipmap.ic_cloudy).into(holder.iv);
        }
    }

    @Override
    public int getItemCount() {
        return dataBeans.size();
    }

    public class myViewHolder extends RecyclerView.ViewHolder{
        private TextView tv_time;
        private ImageView iv;
        public myViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_time = itemView.findViewById(R.id.tv_time);
            iv = itemView.findViewById(R.id.iv);

        }
    }
}
